package cn.edu.xmu.oomall.order.service;

import cn.edu.xmu.javaee.core.model.dto.UserDto;
import cn.edu.xmu.oomall.order.dao.OrderItemDao;
import cn.edu.xmu.oomall.order.dao.bo.OrderItem;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 谢传艳
 * @date 2024/12/13
 */
@Service
@Transactional(propagation = Propagation.REQUIRED)
@RequiredArgsConstructor
public class OrderService {
    private final OrderItemDao orderItemDao;

    /**
     * 根据id查找订单明细
     * @param oid 订单明细id
     * @return 订单明细对象
     */
    public OrderItem findOrderItemById(Long oid) {
        return orderItemDao.findById(oid);
    }

    /**
     * 修改订单明细
     * @param orderItem 订单明细对象
     */
    public OrderItem modifyOrderItem(OrderItem orderItem, UserDto user) {
        OrderItem oldOrderItem = orderItemDao.findById(orderItem.getId());
        return oldOrderItem.modifiedOrderItem(orderItem, user);
    }
}
